package cn.edu.zafu.bigdata.YinMingyan.chapter06;

public class TestGetElement {
    public static void main(String[] args) {
        int[] myArray = {1, 2, 3, 4, 5};
        int indexTure = 3; //测试正常索引
        int indexToGet = 8; //故意设置一个超出数组范围的索引

        try {
            //输出正常索引
            int element = GetElement.getElement(myArray, indexTure);
            System.out.println("元素是: " + element);
            //捕获异常，输出提示信息
            int element2 = GetElement.getElement(myArray, indexToGet);
            System.out.println("元素是: " + element2);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(e.getMessage());
        }
    }
}